package com.wushi.lenovo.asia5b.app_di.inbox.presenter;

import com.mvp.base.BasePresenter;
import com.mvp.base.NetParams;
import com.mvp.common.LocalManageUtil;
import com.wushi.lenovo.asia5b.app_di.inbox.mvpview.InboxActivityView;
import com.wushi.lenovo.asia5b.app_http.ApiService;
import com.wushi.lenovo.asia5b.app_model.other.CountModel;
import com.wushi.lenovo.asia5b.app_model.other.CountType;
import com.wushi.lenovo.asia5b.app_model.other.UserInfo;

import javax.inject.Inject;


/**
 * Created by zhangyuncai on 2019/2/27.
 */
public class InboxActivityPresenter extends BasePresenter<InboxActivityView> {

    ApiService apiService;

    @Inject
    public InboxActivityPresenter(ApiService apiService) {
        this.apiService = apiService;
    }

    /**
     * todo 无优化可能,因为这里是未读消息数量
     */
    public void getMsgCountForOrder() {
        baseSubscribe(apiService.getCount(CountType.Inbox_Order.getCountPath(), UserInfo.getMemberId()),
                new NetParams(false),
                countModelResultModel -> {
                    if (countModelResultModel.getData() == null) {
                        countModelResultModel.setData(new CountModel());
                    }
                    getView().getMsgCountForOrderResult(countModelResultModel.getData().getCount());
                });
    }

    /**
     * todo 无优化可能,因为这里是未读消息数量
     */
    public void getMsgCountForInbox() {
        baseSubscribe(apiService.getMsgInboxCount(UserInfo.getMemberId(), LocalManageUtil.getAppLanguage()),
                new NetParams(false),
                resultModel -> {
                    getView().getMsgCountForInboxResult(resultModel.getCount_unread());
                });
    }

}